import os
import shutil
import pandas as pd
import numpy as np

# 主目录
home_dir = r"/home/linjx"

# 数据集目录
# dataset_dir = os.path.join(home_dir, r"data/dataset/UIUC_AND_NACA_GAN_resample_2000")
dataset_dir = os.path.join(home_dir, r"data", "dataset", "stdAirfoil", "1")

# 结果目录
# result_dir = os.path.join(home_dir, r"data", "cp", "GAN_resample_2000")
result_dir = os.path.join(home_dir, r"data", "cp", "stdAirfoil", "1")


def Init():
    """
        创建目标文件夹
    :return:
    """

    if not os.path.exists("{}".format(result_dir)):
        os.mkdir(r"{}".format(result_dir))


def excute(name):
    os.system('~/bin/foilFlow')
    shutil.copy(r"foilCp.dat", os.path.join(result_dir, "{}.dat".format(name)))


def loop(reverse=False):
    count = 1
    for file_name in os.listdir(dataset_dir):
        df = pd.read_csv(os.path.join(dataset_dir, file_name))
        if reverse:
            df = np.asarray(df)[::-1]
        else:
            df = np.asarray(df)
        np.savetxt("../para/foil.dat", df)
        np.savetxt("../para/foilGeom.dat", df)

        print("{}:cal {}...  ".format(count, file_name[:-4]), end="")
        excute(file_name[:-4])
        print("done!")
        count += 1


if __name__ == "__main__":
    Init()
    loop()
